<!DOCTYPE html>
<html>
<head lang="zh-CN">
	<title>加载中</title>
	<meta charset="UTF-8">
	<meta name="keywords" content="">
	<meta name="description" id="description" content="">
	<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1"/>
	<meta name="format-detection" content="telephone=no, email=no"/>
	<meta name="apple-touch-fullscreen" content="yes">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta http-equiv="Expires" content="-1">
	<meta http-equiv="pragram" content="no-cache">
	<!--css-->
	<link rel="stylesheet" href="css/common.css"/>
	<link rel="stylesheet" href="css/style.css"/>

	<!--js-->
	<script src="js/jquery.min.js"></script>
	<script src="js/flexible.js"></script>
	<script src="js/vue.min.js"></script>
	<script src="js/vant.min.js"></script>
	<script src="js/verify.js"></script>
	<script src="js/wxtool.js?v=4"></script>
</head>
<body>
<div class="wrap Loading">
	<div class="container">
		<div class="logo"><img src="images/logo.png" alt=""></div>
		<div class="loading">
			<span></span>
			<span></span>
			<span></span>
			<span></span>
			<span></span>
		</div>
		<div class="title">加载中...</div>
	</div><!--container-->
</div><!--wrap-->
<script>
	var basePath = '/prod-api/'
	if(window.location.host.indexOf('127.0.0.1')>=0||window.location.host.indexOf('192.168.')>=0||window.location.host.indexOf('localhost')>=0){
		basePath = 'http://zp-www.t.hnic.com.cn/prod-api/'
		basePath = 'http://127.0.0.1:7777'
		console.log('当前属于测试模式'+'=>>>>>>>>>>>>>>>>>>>>>basePath>>>>'+basePath);


	}
	var app = new Vue({
		el: '#app',
		data: {
			phone:'',//手机号
			code:'',//验证码
			verifyFlag:false,//验证标识
			codeName:'获取验证码',
			disabledFlag: false,//获取验证码能否点击
			time: 60,

			wxUser:{
				"authflag": "1",
				"city": "郑州",
				"country": "中国",
				"groupid": 0,
				"headimgurl": "",
				"language": "zh_CN",
				"latitude": 0,
				"longitude": 0,
				"nickname": "测试",
				"openid": "",//关键信息
				"precision": 0,
				"privilege": [],
				"province": "河南",
				"remark": "",
				"remarkname": "",
				"sex": 1,
				"subscribe": 1,
				"subscribeTime": "2017-06-28 18:26:24",
				"subscribe_time": 1498645584,
				"tagid_list": [],
				"unionid": ""//关键信息
			},


		},
		//方法
		methods: {
			//手机号正则验证
			phoneReg:function(v){
				var mobile = /^1(3|4|5|6|7|8|9)\d{9}$/;
				if(mobile.test(v)){
					return true;
				}else{
					return false;
				}
			},


			//
			queryUser(){
				let that = this

				if(null==that.wxUser){
					vant.Toast('请先在微信下授权');
					return false;
				}
				if(null==that.wxUser.unionid||''==that.wxUser.unionid){
					vant.Toast('微信授权失败，未获取unionid');
					return false;
				}
				if(null==that.wxUser.openid||''==that.wxUser.openid){
					vant.Toast('微信授权失败，未获取unionid');
					return false;
				}

				$.ajax({
					type:"POST",
					contentType:'application/json;charset=utf-8',
					dataType:"json",
					url:basePath + "/person/code/loginState?r="+Math.random(),
					data:JSON.stringify({
						"thirdType":'wx.oa',
						"thirdCode":that.wxUser.unionid,
						"secondId":that.wxUser.openid
					}),
					success:function(res){
						console.log(res)
						let flag=res.result.flag;
						if(flag){
							 vant.Toast('亲， 您已经绑定成功了， 可以通过公众号收到消息提醒了');
							window.location.replace("success.html")
						}else {
							window.location.replace("reg.html?r="+Math.random())//
						}
						// if(res.code==200){
						// 	//vant.Toast('绑定成功， 您可以通过公众号收到消息提醒了');
						// 	window.location.replace("success.html")
						// }else{
						// 	vant.Toast(res.message);
						// }
					}
				});
			},


		},
		//生命周期 - 创建完成（可以访问当前this实例）
		created() {
			_wxtool.auth2()
			this.wxUser=_wxtool.getUser();
			console.log(this.wxUser.nickname)
			this.queryUser();
		},
		//生命周期 - 挂载完成（可以访问DOM元素）
		mounted() {

		}
	})
</script>
</body>
</html>
